﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using Habanero.Base;

namespace FireStarter.CodeGeneration
{
    public class LogicTestProjectGenerator : ProjectGenerator
    {
        public override Result Generate()
        {
            CheckRequiredPropertiesSet();
            Directory.CreateDirectory(ProjectPath);

            TemplateLoader templateLoader = new TemplateLoader();

            string contents = templateLoader.GetAssemblyInfo(ProjectName);
            string assemblyInfoFileName = Utilities.CreateFile(ProjectPath, "Properties\\AssemblyInfo.cs", contents);

            string projectFileName = Path.Combine(ProjectPath, ProjectName + ".csproj");
            ProjectFileManager projectFileManager = new ProjectFileManager(projectFileName, OutputType.Library, SolutionGenerator.CodeTemplate);
            projectFileManager.AddProjectReference(ModelSolution.BOProjectName, SolutionGenerator.SolutionDirectory);
            projectFileManager.AddProjectReference(ModelSolution.LogicProjectName, SolutionGenerator.SolutionDirectory);
            if (ModelSolution.BOTestProjectName != null)
            {
                projectFileManager.AddProjectReference(ModelSolution.BOTestProjectName, SolutionGenerator.SolutionDirectory);
            }
            projectFileManager.AddReference(Path.Combine(SolutionGenerator.HabaneroReferencePath, "Habanero.Base.dll"));
            projectFileManager.AddReference(Path.Combine(SolutionGenerator.HabaneroReferencePath, "Habanero.BO.dll"));
            projectFileManager.AddReference(Path.Combine(SolutionGenerator.HabaneroReferencePath, "Habanero.DB.dll"));
            if (!projectFileManager.HasReference("nunit.framework.dll"))
                projectFileManager.AddReference(Path.Combine(SolutionGenerator.HabaneroReferencePath, "nunit.framework.dll"));


            projectFileManager.SaveProjectFile();
            return new Result(true);
        }
    }
}
